package com.gyj.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/*
 * 解析token+校验uri
 */
@Slf4j
@Component
public class AuthFilter implements GlobalFilter, Ordered {

	@Override
	public int getOrder() {
		return 2;
	}

	@Override
	public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
		ServerHttpRequest request = exchange.getRequest();
		String uri = request.getURI().getPath();
		//网关对令牌解析+校验访问uri权限，token校验是否有效
		log.info("访问的uri={}", uri);
		return chain.filter(exchange);
	}

}
